package com.company.Thread;

import javax.sound.midi.Soundbank;
import java.util.logging.SocketHandler;

/**
 * @ProjectName: 复习java
 * @Package: com.company.Thread
 * @ClassName: DeadLockDemo
 * @Author: wym
 * @Date: 2020/10/13 15:49
 * @Version: 1.0
 */

    class res implements Runnable{
        private String locak1;
        private String local2;

        public res(String locak1, String local2) {
            this.locak1 = locak1;
            this.local2 = local2;
        }

        @Override
        public void run()
        {
            synchronized (locak1)
            {
                System.out.println(Thread.currentThread().getName()+locak1+"获取"+local2);
                try { Thread.sleep(1000); }catch (Exception e){ }
                synchronized (local2)
                {
                    System.out.println(Thread.currentThread().getName()+local2+"获取"+locak1);
                }
            }
        }
    }
class Demo {
    public static void main(String[] args) {
        String loclA="locak1";
        String loclB="locak2";
        new Thread(new res(loclA,loclB),"aaa").start();
        new Thread(new res(loclB,loclA),"bbb").start();
    }
}
